package com.hmall.item.service.impl;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {
    @Autowired
    ItemMapper itemMapper;
    @Autowired
    RabbitTemplate rabbitTemplate;


    @Override
    public void saveItem(Item item1) {
        Item item=new Item();
        BeanUtils.copyProperties(item1,item);
        item.setCreateTime(new Date());
        item.setUpdateTime(new Date());
        item.setStatus(1);
        item.setSold(0);
        item.setCommentCount(0);
        itemMapper.insert(item);
        rabbitTemplate.convertAndSend("item.direct","item.update", JSON.toJSONString(item));

    }







}
